package com.viknix.threadpool.manager.config.dump.engine;

import com.viknix.threadpool.manager.config.dump.processor.TpmTaskProcessor;
import com.viknix.threadpool.manager.server.dependence.lifecycle.Closeable;
import com.viknix.threadpool.manager.server.dependence.task.TpmTask;

import java.util.Collection;

/**
 * @Author: Dongqi
 * @Date: 2021/11/22 10:48
 * @Version 1.0
 * @Description: Tpm task execute engine.
 */
public interface TpmTaskExecuteEngine<T extends TpmTask> extends Closeable {

    /**
     * Get Task size in execute engine.
     *
     * @return size of task
     */
    int size();

    /**
     * Whether the execute engine is empty.
     *
     * @return true if the execute engine has no task to do, otherwise false
     */
    boolean isEmpty();

    /**
     * Try to get {@link TpmTaskProcessor} by key, if non-exist, will return default processor.
     *
     * @param key key of task
     * @return task processor for task key or default processor if task processor for task key non-exist
     */
    TpmTaskProcessor getProcessor(Object key);

    /**
     * Get all processor key.
     *
     * @return collection of processors
     */
    Collection<Object> getAllProcessorKey();

    /**
     * Add task into execute pool.
     *
     * @param key  key of task
     * @param task task
     */
    void addTask(Object key, T task);

    /**
     * Remove task.
     *
     * @param key key of task
     * @return tpm task
     */
    T removeTask(Object key);

    /**
     * Get all task keys.
     *
     * @return collection of task keys.
     */
    Collection<Object> getAllTaskKeys();

    /**
     * Set default task processor. If do not find task processor by task key, use this default processor to process
     * task.
     *
     * @param defaultTaskProcessor default task processor
     */
    void setDefaultTaskProcessor(TpmTaskProcessor defaultTaskProcessor);
}
